package city.spring.modules.cardinfo.service.impl;

import city.spring.modules.cardinfo.entity.PhysicalCardChangeLogEmEntity;
import city.spring.modules.cardinfo.repository.PhysicalCardChangeLogEmRepository;
import city.spring.modules.cardinfo.service.PhysicalCardChangeLogEmService;
import city.spring.modules.cardinfo.vo.PhysicalCardChangeLogEmEntityVO;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Service：员工物理卡号更换记录
 *
 * @author pxm
 * @date 2020-12-25 11:53:52
 */
@CacheConfig(cacheNames = {PhysicalCardChangeLogEmServiceImpl.CACHE_NAME})
@Transactional(rollbackFor = Exception.class)
@Service
public class PhysicalCardChangeLogEmServiceImpl extends ServiceImpl<PhysicalCardChangeLogEmRepository, PhysicalCardChangeLogEmEntity> implements PhysicalCardChangeLogEmService {

    @Override
    public void savePhysicalCardChangeLogEm(PhysicalCardChangeLogEmEntity entity) {
        if (!save(entity)) {
            throw new RuntimeException("保存信息失败");
        }
    }

    @Override
    public void updatePhysicalCardChangeLogEm(PhysicalCardChangeLogEmEntity entity) {
        // 使用 updateById(entity); 修改数据时，将会修改 entity 对象中所有非null数据，如果某个字段为null，将会忽略该字段的修改
        if (!updateById(entity)) {
            throw new RuntimeException("修改信息失败");
        }
    }

    @Override
    public void deletePhysicalCardChangeLogEm(String primaryKey) {
        removeById(primaryKey);
    }

    @Override
    public void deletePhysicalCardChangeLogEm(List<String> primaryKeys) {
        removeByIds(primaryKeys);
    }

    @Override
    public IPage<PhysicalCardChangeLogEmEntityVO> staffListPage(Page<? extends PhysicalCardChangeLogEmEntity> page, Wrapper<? extends PhysicalCardChangeLogEmEntity> wrapper) {
        return baseMapper.staffListPage(page, wrapper);
    }
}